home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / misc / yatz.lha / YatZ / src / yatz.c < prev    next >
C/C++ Source or Header  |  1992-07-03  |  17KB  |  726 lines

  1. /*
  2.   Auto: cc   -3 <path><file> +l
  3.   Auto: ln  <path><file>.o -lc +lcdb <path>sound.o -lc16
  4.  */
  5. #include <exec/types.h>
  6. #include <intuition/intuition.h>
  7. #include <libraries/dos.h>
  8. #define DICE 0x30
  9. #define CLOSED 1
  10. #define ROLL 0x40
  11. #define SCORE 3
  12. #define THREEOFAKIND 9
  13. #define FOUROFAKIND 10
  14. #define FULLHOUSE 11
  15. #define SMSTRAIGHT 12
  16. #define LGSTRAIGHT 13
  17. #define YATZ 14
  18. #define CHANCE 15
  19. #define SOME 20
  20. #define NONE 21
  21. #define BONUS 19
  22. #define TOTALLEFT 18
  23. #define INTUITION_REV 33
  24. #define GRAPHICS_REV 33
  25. #define YOFFSET 6
  26. #define DIEMULT 27
  27. #include <dh2:aztec52/progs/yatz/src/yatz.h>        /* make sure this path is */
  28.                                               /* set right!             */
  29. struct IntuitionBase *IntuitionBase = NULL;
  30. struct GfxBase *GfxBase = NULL;
  31. struct Window  *window1 = NULL;
  32. struct RastPort *rp;
  33. char            diepic[6][3][3] =
  34. {"   ",
  35.  " o ",
  36.  "   ",
  37.  
  38.  "o  ",
  39.  "   ",
  40.  "  o",
  41.  
  42.  "o  ",
  43.  " o ",
  44.  "  o",
  45.  
  46.  "o o",
  47.  "   ",
  48.  "o o",
  49.  
  50.  "o o",
  51.  " o ",
  52.  "o o",
  53.  
  54.  "o o",
  55.  "o o",
  56.  "o o"};
  57. LONG            seed;
  58. USHORT          FINISHFLAG = 0;
  59. int             GadFlag = 0;
  60. char            grandstr[20];
  61. int             diceroll[6];
  62. int             highscore;
  63. USHORT          leaveprog = FALSE;
  64. int             rollcount = 0;
  65. USHORT          havesound = TRUE;
  66. int             scores[20] =
  67. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  68. short           scoretable[15] =
  69. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  70. int             dicegad[6] =
  71. {0, 0, 0, 0, 0, 0};
  72. struct TextAttr myAttr =
  73. {(UBYTE *) "topaz.font", 8, 0, 0};
  74. struct TextFont *tf;
  75.  
  76. VOID 
  77. cleanExit(returnValue)
  78.     int             returnValue;
  79. {
  80.     if (havesound)
  81.      cleanup();
  82.     if (window1)
  83.     CloseWindow(window1);
  84.     if (tf)
  85.      CloseFont (tf);
  86.     if (GfxBase)
  87.     CloseLibrary((struct Library *) GfxBase);
  88.     if (IntuitionBase)
  89.     CloseLibrary((struct Library *) IntuitionBase);
  90.     exit(returnValue);
  91. }
  92.  
  93.  
  94. VOID 
  95. OpenAll(VOID)
  96. {
  97.     int             hs;
  98.     struct RastPort *rp;
  99.     IntuitionBase = (struct IntuitionBase *)
  100.     OpenLibrary("intuition.library", INTUITION_REV);
  101.     if (IntuitionBase == NULL)
  102.     cleanExit(RETURN_WARN);
  103.     GfxBase = (struct GfxBase *)
  104.     OpenLibrary("graphics.library", GRAPHICS_REV);
  105.     if (GfxBase == NULL)
  106.     cleanExit(RETURN_WARN);
  107.  
  108.     window1 = (struct Window *) OpenWindow(&NewWindowStructure1);
  109.     if (window1 == NULL)
  110.     cleanExit(RETURN_WARN);
  111.     if ((hs = fopen("yatz.hs", "r")) != NULL) {
  112.     fscanf(hs, "%d", &highscore);
  113.     fclose(hs);
  114.     } else {
  115.     if ((hs = fopen("yatz.hs", "w")) != NULL) {
  116.         highscore = 0;
  117.         fprintf(hs, "%d", highscore);
  118.         fclose(hs);
  119.     }
  120.     }
  121.     if (loadSound("diceroll") == 20)
  122.             havesound = FALSE; 
  123.     rp = window1->RPort;
  124.     tf = (struct TextFont *)OpenFont (&myAttr);
  125.     if (tf == NULL) cleanExit (RETURN_WARN);
  126.     SetFont(rp, tf);
  127. }
  128.  
  129. VOID 
  130. ShowHighScore()
  131. {
  132.     Move(rp, 352, 145+YOFFSET);
  133.     SetDrMd(rp, JAM2);
  134.     if (highscore < 10)
  135.     sprintf(grandstr, "  %d", highscore);
  136.     else if (highscore < 100)
  137.     sprintf(grandstr, " %d", highscore);
  138.     else
  139.     sprintf(grandstr, "%d", highscore);
  140.     Text(rp, grandstr, 3);
  141. }
  142.  
  143. VOID 
  144. RollAllDice()
  145. {
  146.     int             counter;
  147.     for (counter = 1; counter < 6; counter++)
  148.     diceroll[counter] = RollDie(counter);
  149.     if (havesound == TRUE)
  150.         soundSound();
  151. }
  152.  
  153.  
  154. int 
  155. RollDie(diepos)
  156.     USHORT          diepos;
  157. {
  158.     int             die;
  159.     die = rand();
  160.     die = die / 5462;
  161.     die++;
  162.     SetDrMd(rp, JAM2);
  163.     Move(rp, 22, (DIEMULT * diepos) - 2 + YOFFSET);
  164.     Text(rp, &diepic[die - 1][0], 3);
  165.     Move(rp, 22, (DIEMULT * diepos) + 5 + YOFFSET);
  166.     Text(rp, &diepic[die - 1][1], 3);
  167.     Move(rp, 22, (DIEMULT * diepos) + 12 + YOFFSET);
  168.     Text(rp, &diepic[die - 1][2], 3);
  169.  
  170.     return die;
  171. }
  172.  
  173. VOID 
  174. UnGhostDice()
  175. {
  176.     RemoveGList(window1, &Gadget8, 5);
  177.     Gadget8.Flags = Gadget8.Flags & ~GADGDISABLED;
  178.     Gadget9.Flags = Gadget9.Flags & ~GADGDISABLED;
  179.     Gadget10.Flags = Gadget10.Flags & ~GADGDISABLED;
  180.     Gadget11.Flags = Gadget11.Flags & ~GADGDISABLED;
  181.     Gadget12.Flags = Gadget12.Flags & ~GADGDISABLED;
  182.     AddGList (window1, &Gadget8, 0, 5, NULL);
  183.     SetDrMd(rp, JAM2 | INVERSVID);
  184.     RectFill(rp, 15, 15 + YOFFSET, 54, 150 + YOFFSET);
  185.     RefreshGList(&Gadget8, window1, NULL, 5);
  186. }
  187.  
  188. VOID 
  189. GhostDice()
  190. {
  191.     RemoveGList(window1, &Gadget8, 5);
  192.     Gadget8.Flags = Gadget8.Flags | GADGDISABLED;
  193.     Gadget9.Flags = Gadget9.Flags | GADGDISABLED;
  194.     Gadget10.Flags = Gadget10.Flags | GADGDISABLED;
  195.     Gadget11.Flags = Gadget11.Flags | GADGDISABLED;
  196.     Gadget12.Flags = Gadget12.Flags | GADGDISABLED;
  197.     AddGList (window1, &Gadget8, 0, 5, NULL);
  198.     RefreshGList(&Gadget8, window1, NULL, 5);
  199. }
  200.  
  201. SHORT 
  202. RollSelected()
  203. {
  204.     int             counter;
  205.     int             status = NONE;
  206.     for (counter = 1; counter < 6; counter++)
  207.     if (dicegad[counter] == 1) {
  208.         dicegad[counter] = 0;
  209.         switch (counter) {
  210.         case 1:
  211.         RefreshGList(&Gadget8, window1, NULL, 1);
  212.         Gadget8.Flags = NULL;
  213.         status = SOME;
  214.         break;
  215.         case 2:
  216.         RefreshGList(&Gadget9, window1, NULL, 1);
  217.         Gadget9.Flags = NULL;
  218.         status = SOME;
  219.         break;
  220.         case 3:
  221.         RefreshGList(&Gadget10, window1, NULL, 1);
  222.         Gadget10.Flags = NULL;
  223.         status = SOME;
  224.         break;
  225.         case 4:
  226.         RefreshGList(&Gadget11, window1, NULL, 1);
  227.         Gadget11.Flags = NULL;
  228.         status = SOME;
  229.         break;
  230.         case 5:
  231.         RefreshGList(&Gadget12, window1, NULL, 1);
  232.         Gadget12.Flags = NULL;
  233.         status = SOME;
  234.         break;
  235.         }
  236.         diceroll[counter] = RollDie(counter);
  237.     }
  238.     if ((rollcount == 1) && (status == SOME))
  239.          GhostDice();
  240.     if ( (status == SOME) && (havesound == TRUE) )
  241.     soundSound();
  242.     return status;
  243.  
  244. }
  245.  
  246. USHORT 
  247. handleIDCMP(struct Window * win)
  248. {
  249.     int             flag = 0;
  250.     struct IntuiMessage *message = NULL;
  251.     int             code;
  252.     USHORT          id;
  253.     int             dicenum;
  254.     ULONG           class;
  255.     struct Gadget  *g;
  256.     while (message = (struct IntuiMessage *) GetMsg(win->UserPort)) {
  257.     class = message->Class;
  258.     code = message->Code;
  259.     g = (struct Gadget *) (message->IAddress);
  260.     ReplyMsg((struct Message *) message);
  261.     switch (class) {
  262.     case CLOSEWINDOW:
  263.         flag = CLOSED;
  264.         break;
  265.     case GADGETDOWN:
  266.         id = g->GadgetID;
  267.         dicenum = id - DICE;
  268.         dicenum++;
  269.         if ((dicegad[dicenum]) == 1)
  270.         dicegad[dicenum] = 0;
  271.         else
  272.         dicegad[dicenum] = 1;
  273.         break;
  274.     case GADGETUP:
  275.         flag = g->GadgetID;
  276.         break;
  277.     }
  278.     }
  279.     return (flag);
  280. }
  281.  
  282. VOID 
  283. DoDigits()
  284. {
  285.     int             digit, counter;
  286.     char            temp[20];
  287.     digit = GadFlag - 2;
  288.     scores[digit] = 0;
  289.     for (counter = 1; counter < 6; counter++)
  290.     if (diceroll[counter] == digit)
  291.         scores[digit]++;
  292.     scores[digit] = scores[digit] * digit;
  293.     Move(rp, 198, 11 + (14 * digit) + YOFFSET);
  294.     if (scores[digit] < 10)
  295.     sprintf(temp, " %d", scores[digit]);
  296.     else
  297.     sprintf(temp, "%d", scores[digit]);
  298.     Text(rp, temp, 2);
  299. }
  300.  
  301. USHORT 
  302. NumLeftBlanks()
  303. {
  304.     USHORT          counter, blanks = 6;
  305.     for (counter = 0; counter < 7; counter++)
  306.     if (scoretable[counter] == 1)
  307.         blanks--;
  308.     return blanks;
  309. }
  310.  
  311. USHORT 
  312. NumRightBlanks()
  313. {
  314.     USHORT          counter, blanks = 7;
  315.     for (counter = 7; counter < 16; counter++)
  316.     if (scoretable[counter] == 1)
  317.         blanks--;
  318.     return blanks;
  319. }
  320.  
  321. int 
  322. DoBonus()
  323. {
  324.     int             total = 0;
  325.     USHORT          counter;
  326.     for (counter = 0; counter < 7; counter++)
  327.     total = total + scores[counter];
  328.     return total;
  329. }
  330.  
  331. VOID 
  332. DoGrand()
  333. {
  334.     int             hs;
  335.     USHORT          counter, totals = 0;
  336.     if ((NumLeftBlanks() == 0) && NumRightBlanks() == 0) {
  337.     FINISHFLAG = 1;
  338.     for (counter = 7; counter < 15; counter++)
  339.         totals = totals + scores[counter];
  340.     totals = totals + scores[TOTALLEFT];
  341.     totals = totals + scores[BONUS];
  342.     sprintf(grandstr, "%u", totals);
  343.     if (totals < 100)
  344.         sprintf(grandstr, " %u", totals);
  345.     Move(rp, 352, 132 + YOFFSET);
  346.     Text(rp, grandstr, 3);
  347.     if (totals > highscore)
  348.         if ((hs = fopen("yatz.hs", "w")) != NULL) {
  349.         highscore = totals;
  350.         fprintf(hs, "%d", highscore);
  351.         fclose(hs);
  352.         ShowHighScore();
  353.         }
  354.     }
  355. }
  356.  
  357. VOID 
  358. DoneRolls()
  359. {
  360.     USHORT counter;
  361.     ULONG           signalmask, signals;
  362.     signalmask = 1L << window1->UserPort->mp_SigBit;
  363.     DoGrand();
  364.     for (counter = 1; counter < 6; counter++)
  365.     dicegad[counter] = 0;
  366.     Gadget8.Flags = NULL;
  367.     Gadget9.Flags = NULL;
  368.     Gadget10.Flags = NULL;
  369.     Gadget11.Flags = NULL;
  370.     Gadget12.Flags = NULL;
  371.     SetDrMd(rp, JAM2 | INVERSVID);
  372.     RectFill(rp, 15, 15 + YOFFSET, 54, 150 + YOFFSET);
  373.     RefreshGList(&Gadget8, window1, NULL, 5);    /* Get Rid of Dice */
  374.     GhostDice();
  375.     if (FINISHFLAG != 1) {
  376.     while ((GadFlag != ROLL) && (GadFlag != CLOSED)) {
  377.         signals = Wait(signalmask);
  378.         if (signals & signalmask)
  379.         GadFlag = handleIDCMP(window1);
  380.     }
  381.     if (GadFlag != CLOSED) {
  382.         UnGhostDice();
  383.         RollAllDice();
  384.     }
  385.     }
  386. }
  387.  
  388. USHORT 
  389. CheckThree()
  390. {
  391.     char           tempstr[20];
  392.     USHORT          result = 0, counter, total = 0, temp[7] =
  393.     {0, 0, 0, 0, 0, 0, 0};
  394.     for (counter = 1; counter < 6; counter++) {
  395.     temp[diceroll[counter] - 1]++;
  396.     total = total + diceroll[counter];
  397.     }
  398.  
  399.     for (counter = 0; counter < 6; counter++)
  400.     if (temp[counter] >= 3)
  401.         result = 1;
  402.     if (result != 1)
  403.     total = 0;
  404.     if (GadFlag != FULLHOUSE) {
  405.     scores[GadFlag - 2] = total;
  406.     Move(rp, 360, 25 + YOFFSET);
  407.     if (total < 10)
  408.         sprintf(tempstr, " %u", total);
  409.     else
  410.         sprintf(tempstr, "%u", total);
  411.     Text(rp, tempstr, 2);
  412.     }
  413.     return result;
  414. }
  415.  
  416.  
  417. USHORT 
  418. CheckFour()
  419. {
  420.     char           tempstr[20];
  421.     USHORT          result = 0, counter, total = 0, temp[7] =
  422.     {0, 0, 0, 0, 0, 0, 0};
  423.     for (counter = 1; counter < 6; counter++) {
  424.     temp[diceroll[counter] - 1]++;
  425.     total = total + diceroll[counter];
  426.     }
  427.  
  428.     for (counter = 0; counter < 6; counter++)
  429.     if (temp[counter] >= 4)
  430.         result = 1;
  431.  
  432.     if (result != 1)
  433.     total = 0;
  434.     scores[GadFlag - 2] = total;
  435.     Move(rp, 360, 39 + YOFFSET);
  436.     if (total < 10)
  437.     sprintf(tempstr, " %u", total);
  438.     else
  439.     sprintf(tempstr, "%u", total);
  440.     Text(rp, tempstr, 2);
  441.     return result;
  442. }
  443.  
  444. USHORT 
  445. CheckFullHouse()
  446. {
  447.     USHORT          result = 0, counter, temp[7] =
  448.     {0, 0, 0, 0, 0, 0, 0};
  449.     for (counter = 1; counter < 6; counter++)
  450.     temp[diceroll[counter] - 1]++;
  451.  
  452.     for (counter = 0; counter < 6; counter++)
  453.     if (temp[counter] == 2)
  454.         result = 1;
  455.  
  456.     if ((result == 1) && (CheckThree() == 1)) {
  457.     scores[GadFlag - 2] = 25;
  458.     Move(rp, 360, 53 + YOFFSET);
  459.     Text(rp, "25", 2);
  460.     } else {
  461.     result = 0;
  462.     scores[GadFlag - 2] = 0;
  463.     Move(rp, 360, 53 + YOFFSET);
  464.     Text(rp, " 0", 2);
  465.     }
  466.     return result;
  467. }
  468.  
  469. USHORT 
  470. CheckSmStraight()
  471. {
  472.     USHORT          result = 0, counter, total = 0, temp[7] =
  473.     {0, 0, 0, 0, 0, 0, 0};
  474.     for (counter = 1; counter < 6; counter++)
  475.     temp[diceroll[counter] - 1]++;
  476.     total = 0;
  477.     for (counter = 0; counter < 6; counter++) {
  478.     if (temp[counter] >= 1)
  479.         total++;
  480.     else {
  481.         if (temp[counter] == 0)
  482.         total = 0;
  483.     }
  484.     if (total == 4)
  485.         result = 1;
  486.     }
  487.     if (result == 1) {
  488.     scores[GadFlag - 2] = 30;
  489.     Move(rp, 360, 67 + YOFFSET);
  490.     Text(rp, "30", 2);
  491.     } else {
  492.     scores[GadFlag - 2] = 0;
  493.     Move(rp, 360, 67 + YOFFSET);
  494.     Text(rp, " 0", 2);
  495.     }
  496.     return result;
  497. }
  498.  
  499. USHORT 
  500. CheckLgStraight()
  501. {
  502.     USHORT          result = 0, counter, total = 0, temp[7] =
  503.     {0, 0, 0, 0, 0, 0, 0};
  504.     for (counter = 1; counter < 6; counter++)
  505.     temp[diceroll[counter] - 1]++;
  506.     total = 0;
  507.     for (counter = 0; counter < 6; counter++) {
  508.     if (temp[counter] >= 1)
  509.         total++;
  510.     else {
  511.         if (temp[counter] == 0)
  512.         total = 0;
  513.     }
  514.     if (total == 5)
  515.         result = 1;
  516.     }
  517.     if (result == 1) {
  518.     scores[GadFlag - 2] = 40;
  519.     Move(rp, 360, 81 + YOFFSET);
  520.     Text(rp, "40", 2);
  521.     } else {
  522.     scores[GadFlag - 2] = 0;
  523.     Move(rp, 360, 81 + YOFFSET);
  524.     Text(rp, " 0", 2);
  525.     }
  526.  
  527.     return result;
  528. }
  529.  
  530. USHORT 
  531. CheckYatz()
  532. {
  533.     char           tempstr[20];
  534.     USHORT          result = 0, counter, total = 0, temp[7] =
  535.     {0, 0, 0, 0, 0, 0, 0};
  536.     for (counter = 1; counter < 6; counter++)
  537.     temp[diceroll[counter] - 1]++;
  538.     total = 0;
  539.     for (counter = 0; counter < 6; counter++)
  540.     if (temp[counter] == 5)
  541.         result = 1;
  542.     if (result == 1) {
  543.     scores[GadFlag - 2] = scores[GadFlag - 2] + 50;
  544.     if (scoretable[GadFlag - 2] == 0)
  545.         scores[GadFlag - 2] = 50;
  546.     Move(rp, 352, 95 + YOFFSET);
  547.     if (scores[GadFlag - 2] == 50)
  548.         Text(rp, " 50", 3);
  549.     else {
  550.         sprintf(tempstr, "%d", scores[GadFlag - 2]);
  551.         Text(rp, tempstr, 3);
  552.     }
  553.     } else if (scores[GadFlag - 2] == 0) {
  554.     Move(rp, 352, 95 + YOFFSET);
  555.     Text(rp, "  0", 3);
  556.     }
  557.     return result;
  558. }
  559.  
  560. VOID 
  561. DoChance()
  562. {
  563.     char           tempstr[20];
  564.     USHORT          counter, total = 0;
  565.     for (counter = 1; counter < 6; counter++)
  566.     total = total + diceroll[counter];
  567.     scores[GadFlag - 2] = total;
  568.     Move(rp, 360, 109 + YOFFSET);
  569.     if (total < 10)
  570.     sprintf(tempstr, " %u", total);
  571.     else
  572.     sprintf(tempstr, "%u", total);
  573.     Text(rp, tempstr, 2);
  574. }
  575.  
  576.  
  577. VOID 
  578. DoTotal()
  579. {
  580.     USHORT          total;
  581.     char           tempstr[20];
  582.     if ((NumLeftBlanks() == 0) && (scores[TOTALLEFT] == 0)) {
  583.     scores[TOTALLEFT] = DoBonus();
  584.  
  585.     if (scores[TOTALLEFT] >= 63) {
  586.         scores[BONUS] = 35;
  587.         Move(rp, 198, 118 + YOFFSET);
  588.         Text(rp, "35", 2);
  589.     } else {
  590.         Move(rp, 198, 118 + YOFFSET);
  591.         Text(rp, " 0", 2);
  592.     }
  593.     total = scores[TOTALLEFT];
  594.     Move(rp, 190, 109 + YOFFSET);
  595.     if (total < 10)
  596.         sprintf(tempstr, "  %u", total);
  597.     else
  598.         sprintf(tempstr, " %u", total);
  599.     Text(rp, tempstr, 3);
  600.     }
  601. }
  602.  
  603.  
  604. VOID 
  605. DoRestart()
  606. {
  607.     ULONG           signalmask, signals;
  608.     int             counter;
  609.     signalmask = 1L << window1->UserPort->mp_SigBit;
  610.     for (counter = 0; counter < 20; counter++)
  611.     scores[counter] = 0;
  612.     for (counter = 0; counter < 15; counter++)
  613.     scoretable[counter] = 0;
  614.     while ((GadFlag != ROLL) && (GadFlag != CLOSED)) {
  615.     signals = Wait(signalmask);
  616.     if (signals & signalmask)
  617.         GadFlag = handleIDCMP(window1);
  618.     }
  619.     if (GadFlag != CLOSED) {
  620.         RemoveGList(window1, &Gadget8, 5);
  621.         Gadget8.Flags = Gadget8.Flags & ~GADGDISABLED;
  622.         Gadget9.Flags = Gadget9.Flags & ~GADGDISABLED;
  623.         Gadget10.Flags = Gadget10.Flags & ~GADGDISABLED;
  624.         Gadget11.Flags = Gadget11.Flags & ~GADGDISABLED;
  625.         Gadget12.Flags = Gadget12.Flags & ~GADGDISABLED;
  626.         AddGList (window1, &Gadget8, 0, 5, NULL);
  627.         SetDrMd(rp, JAM2 | INVERSVID);
  628.         RectFill(rp, 1, 10 + YOFFSET, 375, 150 + YOFFSET);
  629.         RefreshGList(&Gadget8, window1, NULL, -1);
  630.         ShowHighScore();
  631.     RollAllDice();
  632.     }
  633.      else leaveprog = TRUE;
  634.     FINISHFLAG = 0;
  635. }
  636.  
  637. VOID 
  638. main()
  639. {
  640.     ULONG           signalmask, signals;
  641.     OpenAll();
  642.     seed = time(NULL);
  643.     srand((USHORT) seed);
  644.     signalmask = 1L << window1->UserPort->mp_SigBit;
  645.     rp = window1->RPort;
  646.     SetAPen(rp, 1);
  647.     ShowHighScore();
  648.     while ((GadFlag != ROLL) && (GadFlag != CLOSED)) {
  649.     signals = Wait(signalmask);
  650.     if (signals & signalmask)
  651.         GadFlag = handleIDCMP(window1);
  652.     }
  653.     if (GadFlag != CLOSED) {
  654.          UnGhostDice();
  655.      RollAllDice();
  656.          }
  657.        else
  658.         {
  659.         cleanupsome();
  660.         havesound = FALSE;
  661.         }
  662.     
  663.            while (GadFlag != CLOSED) {
  664.         if (FINISHFLAG == 1)
  665.         DoRestart();
  666.             if (leaveprog != TRUE)
  667.           {
  668.         signals = Wait(signalmask);
  669.         if (signals & signalmask)
  670.         GadFlag = handleIDCMP(window1);
  671.         if ((GadFlag == ROLL) && (rollcount < 2)) {
  672.         if (RollSelected() == NONE)
  673.             rollcount--;
  674.         rollcount++;
  675.         } else if ((GadFlag >= SCORE) && (GadFlag <= SCORE + 5) && (scoretable[GadFlag - 2] == 0)) {
  676.         DoDigits();
  677.         scoretable[GadFlag - 2] = 1;
  678.         rollcount = 0;
  679.         DoTotal();
  680.         DoneRolls();
  681.         } else if ((GadFlag == THREEOFAKIND) && (scoretable[GadFlag - 2] == 0)) {
  682.         CheckThree();
  683.         scoretable[GadFlag - 2] = 1;
  684.         rollcount = 0;
  685.         DoneRolls();
  686.         } else if ((GadFlag == FOUROFAKIND) && (scoretable[GadFlag - 2] == 0)) {
  687.         CheckFour();
  688.         scoretable[GadFlag - 2] = 1;
  689.         rollcount = 0;
  690.         DoneRolls();
  691.         } else if ((GadFlag == FULLHOUSE) && (scoretable[GadFlag - 2] == 0)) {
  692.         CheckFullHouse();
  693.         scoretable[GadFlag - 2] = 1;
  694.         rollcount = 0;
  695.         DoneRolls();
  696.         } else if ((GadFlag == SMSTRAIGHT) && (scoretable[GadFlag - 2] == 0)) {
  697.         CheckSmStraight();
  698.         scoretable[GadFlag - 2] = 1;
  699.         rollcount = 0;
  700.         DoneRolls();
  701.         } else if ((GadFlag == LGSTRAIGHT) && (scoretable[GadFlag - 2] == 0)) {
  702.         CheckLgStraight();
  703.         scoretable[GadFlag - 2] = 1;
  704.         rollcount = 0;
  705.         DoneRolls();
  706.         } else if ((GadFlag == YATZ) && ((scoretable[GadFlag - 2] == 0)
  707.                          || (scores[GadFlag - 2] > 0))) {
  708.         if ((CheckYatz() == 1) || (scoretable[GadFlag-2] == 0))
  709.                 {
  710.         scoretable[GadFlag - 2] = 1;
  711.         rollcount = 0;
  712.         DoneRolls();
  713.                 }
  714.         } else {
  715.         if ((GadFlag == CHANCE) && (scoretable[GadFlag - 2] == 0)) {
  716.             scoretable[GadFlag - 2] = 1;
  717.             DoChance();
  718.             rollcount = 0;
  719.             DoneRolls();
  720.         }
  721.         }
  722.          }
  723.     }
  724.     cleanExit(RETURN_OK);
  725. }
  726.